package digital.store.springmvc.controller;

import java.util.Collection;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import digital.store.springmvc.service.CategoryService;
import digital.store.springmvc.service.ProductService;
import digital.store.tutorial.springmvc.model.Category;
import digital.store.tutorial.springmvc.model.Product;

@Controller
@RequestMapping(value="/user")
public class UserCategoryController {
	@Autowired
	private ProductService productService;
	
	@Autowired
	private CategoryService categoryService;
	
	@RequestMapping(value = "{id}", method = RequestMethod.GET)
	public String showEditForm(@PathVariable Long id, Model model) {
		Collection<Product> products = productService.findByCategoryId(id);
		Category category = categoryService.findById(id);
        model.addAttribute("productsUser",products);
        model.addAttribute("categoryUser", category);
        return "user/user-category";
    }
}
